﻿using System;
using System.Collections.Generic;
using System.Xml;
using umbraco.MacroEngines;
using umbraco.MacroEngines.Library;

namespace uComponents.RazorModels.MultiNodeTreePicker
{
	[RazorDataTypeModel("C2D6894B-E788-4425-BCF2-308568E3D38B")]
	public class MultiNodeTreePickerModelBinder : IRazorDataTypeModel
	{
		public bool Init(int CurrentNodeId, string PropertyData, out object instance)
		{
			var nodeIds = Helper.CouldItBeXml(PropertyData) ? Helper.GetXmlIds(PropertyData) : Helper.GetCsvIds(PropertyData);
			var library = new RazorLibraryCore(null);

			instance = (library.NodesById(nodeIds) as DynamicNodeList);

			return true;
		}
	}
}
